﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DTO;
using BUS;

namespace GUI
{
    public partial class FormDanhSachLichDi : Form
    {
        public FormDanhSachLichDi()
        {
            InitializeComponent();
        }

        private void FormDanhSachLichDi_Load(object sender, EventArgs e)
        {
            List<String> mc = ChuyenXeBUS.SelectALLMaChuyen();

            foreach (var item in mc)
            {
                this.cbbMaChuyen.Items.Add(item);
            }
            this.cbbMaChuyen.SelectedItem = mc[0].ToString();
            String machuyen = cbbMaChuyen.Text.ToString();
            //this.dataGridViewLichDi.DataSource = LichDiBUS.SelectLichDiByMaChuyen(machuyen);
        }

        private void cbbMaChuyen_SelectedIndexChanged(object sender, EventArgs e)
        {
            //String machuyen = cbbMaChuyen.Text.ToString();
            //this.dataGridViewLichDi.Columns.Clear();
            //this.dataGridViewLichDi.DataSource = LichDiBUS.SelectLichDiByMaChuyen(machuyen);
            //this.lblTong.Text = this.dataGridViewLichDi.Rows.Count.ToString();
        }

        private void btnXem_Click(object sender, EventArgs e)
        {
            this.dataGridViewLichDi.Columns.Clear();
            int tong=0;
            String machuyen = cbbMaChuyen.Text.ToString();
            String ngaybd = dtpBatDau.Value.Year.ToString() + "/" + dtpBatDau.Value.Month.ToString() + "/" + dtpBatDau.Value.Day.ToString() ;
            String ngaykt = dtpKetThuc.Value.Year.ToString() + "/" +  dtpKetThuc.Value.Month.ToString() + "/" +  dtpKetThuc.Value.Day.ToString() ;
            try
            {
                this.dataGridViewLichDi.DataSource = LichDiBUS.SelectSoluongchuyen(machuyen, ngaybd, ngaykt, ref tong);
                lblTongChuyen.Text = tong.ToString();
                this.lblTongChuyen.Text = tong.ToString();
                this.lblTong.Text = this.dataGridViewLichDi.Rows.Count.ToString();
            }
            catch (Exception ex) {
                MessageBox.Show(ex.Message);
            }
        }

        private void lblTong_Click(object sender, EventArgs e)
        {

        }
    }
}

